package com.hj.ipproxy.thread;

public class Build {
	private boolean subFirst = true;
	public synchronized void sub(int i){
		if (!subFirst) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		for (int j = 1; j <= 10; j++) {
			System.out.println("子线程："+i+"循环"+j+"次");
		}
		subFirst = false;
		this.notify();
	}
	
	public synchronized void main(int i){
		if (subFirst) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		for (int j = 1; j <= 10; j++) {
			System.err.println("主线程："+i+"循环"+j+"次");
		}
		subFirst = true;
		this.notify();
	}
	
}
class Auild{
	private static int num = 0;
	public synchronized void add(){
		num++;
		//System.out.println(Thread.currentThread().getName()+"---"+num);
	}
	public void handle(int i, ThreadMain tm){
		for (int j = 0; j < 10; j++) {
			tm.add(i);
		}
		System.out.println("---"+num);
		add();
		if (num == 3) {
			synchronized (tm) {
				tm.notify();
			}
		}
	}
}
